package com.cy.pj.sys.service.impl;


import com.cy.pj.common.web.pojo.Input;
import com.cy.pj.sys.dao.ApprovalDao;
import com.cy.pj.sys.pojo.Approval;
import com.cy.pj.sys.service.IToDoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ToDoService implements IToDoService {

    @Autowired
    ApprovalDao approvalDao;

    @Override
    public void generateTodo(Input input) {
        Approval approval = input.getApproval();
        approval.setStatus(1);
        approvalDao.updateApproval(approval);
    }

    @Override
    public void pass(Input input) {
        input.setApproval(this.getTodo(input));
        input.getApproval().setStatus(2);
    }

    @Override
    public void reject(Input input) {
        String reajectReason = input.getApproval().getRejectReason();
        input.setApproval(this.getTodo(input));
        input.getApproval().setStatus(3);
        input.getApproval().setRejectReason(reajectReason);
    }

    @Override
    public Approval getTodo(Input input) {
        Long approvalId = input.getApproval().getApprovalId();
        Approval approval = approvalDao.selectById(approvalId);
        return approval;
    }
}
